package com.jiahe.blog.controller;

import com.jiahe.blog.model.response.BlogResponse;
import com.jiahe.blog.model.vo.UserVO;
import com.jiahe.blog.service.UserAuthService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

@Api(tags = "用户账号模块")
@RestController
public class UserAuthController {

    @Autowired
    private UserAuthService userAuthService;

    @ApiOperation(value = "发送邮箱验证码")
    @ApiImplicitParam(name = "username", value = "用户名", required = true, dataType = "String")
    @GetMapping("/users/code")
    public BlogResponse<Void> sendCode(String username) {
        userAuthService.sendCode(username);
        return BlogResponse.success("发送成功", null);
    }

    @ApiOperation(value = "用户注册")
    @PostMapping("/users")
    public BlogResponse<Void> saveUser(@Valid @RequestBody UserVO userVO) {
        userAuthService.saveUser(userVO);
        return BlogResponse.success("注册成功", null);
    }
}
